<?php

/***
 * 描述：库存模型  
 * 
 * @category		Lib
 * @package			Model			
 * @subpackage	
 * @author			wanght <whtaok@gmail.com>
 * @since			2013-7-30
 * @version			$Id: StockModel.class.php 12 2013-10-22 08:31:42Z whtaok@gmail.com $
 */
class StockModel {
	/**
	 * 描述：订单提交成功后，更新商品库存信息
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @param 		string 	$shop_id		商铺ID
	 * @param 		string 	$order_code		订单号
	 * @param 		array	$order_code		订单商品的库存相关信息prod_id,num,spec_qty,stock_prod_id为必须项
	 * @since		2013-4-21
	 */
	public static function updOrderStock($shop_id,$orderCode,$orderProdList){
		$isSaveLog = false;
		$mod = new ProductPriceModel();
		$modWhere['shop_id'] = $shop_id;
		foreach ($orderProdList as $key=>$value){
			$modWhere['prod_id'] = $value['stock_prod_id'];
			if($modWhere['prod_id']==0){
				$modWhere['prod_id'] =  $value['prod_id'];
			}
			$num = $value['num'] * $value['spec_qty'];
			$flag = $mod->where($modWhere)->setDec('stock_qty',$num);
			if($flag===false){
				//记录日志：库存更新失败
				//Log::record($shop_id.','.$orderCode.','.implode(',', $value));
				//$isSaveLog = true;
			}
		}
		if($isSaveLog){
			//Log::save('','E:/project/workspace6/log/'.$shop_id.'/updOrderStock.log');
		}
	}
	
	public static function updOrderStockTuangou($orderCode,$prod_id,$prod_num){
		$isSaveLog = false;
		$mod = new CommonModel('TuangouLib');
		$modWhere['id'] = $prod_id;
		$flag = $mod->where($modWhere)->setDec('stock_qty',$prod_num);
		if($flag===false){
			//记录日志：库存更新失败
			//Log::record($shop_id.','.$orderCode.','.implode(',', $value));
			//$isSaveLog = true;
		}
		if($isSaveLog){
			//Log::save('','E:/project/workspace6/log/'.$shop_id.'/updOrderStock.log');
		}		
	}
}

?>